package com.vcredit.creditcat.service;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.AuthPersonalAddress;
import com.vcredit.creditcat.model.AuthPersonalInfo;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.persistence.base.AuthPersonalInfoMapper;
import com.vcredit.creditcat.vo.auth.AuthPersonalInfoExt;

/**
 * 
 **/
@Service
public class AuthPersonalInfoService {
	@Autowired
	private AuthPersonalInfoMapper mapper;
	
	@Autowired
	private AuthPersonalAddressService authPersonalAddressService;

	public void insert(AuthPersonalInfo obj) {
		mapper.insert(obj);
	}

	public void update(AuthPersonalInfo obj) {
		mapper.update(obj);
	}

	public AuthPersonalInfo findByProcessId(Long processId) {
		return mapper.findByProcessId(processId);
	}

	public List<AuthPersonalInfo> findAll() {
		return mapper.findAll();
	}

	public List<AuthPersonalInfo> find(AuthPersonalInfo obj) {
		return mapper.find(obj);
	}
	
	public AuthPersonalInfoExt findExtByCust(Cust cust) {
		AuthPersonalInfo personalInfo = this.findByProcessId(cust.getLastProccessId());
		if(null == personalInfo) {
			personalInfo = new AuthPersonalInfo();
		}
		
		AuthPersonalInfoExt target = new AuthPersonalInfoExt();
		BeanUtils.copyProperties(personalInfo, target);
		
		// 查询用户基本信息的扩展（基本信息地址表）
		List<AuthPersonalAddress> personalAddrList = authPersonalAddressService.findByCustId(cust.getCustId(), null);
		target.setPersonalAddrList(personalAddrList);
		
		return target;
	}
}